<template>
  <el-form 
    ref="folder"
    :model="ruleForm"
    :rules="rules"
    label-width="80px"
    class="folder"
    :size="formSize"
    status-icon
  >
    <el-form-item required label="文件夹名" prop="folderName">
      <el-input placeholder="最多支持255个字符" v-model="ruleForm.folderName" :suffix-icon="EnhancedInfoFilled">
      </el-input>
    </el-form-item>
  </el-form>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import EnhancedInfoFilled from './EnhancedInfoFilled.vue'

import { FOLDERNAME_REG } from '../utils';

const validateFoldername = ( rule: any, value: any, callback: any ) => {
  if (value === '') {
    callback(new Error('文件夹名称不能为空！'))
  } else {
    if (!FOLDERNAME_REG.test(value)) {
      callback(new Error("文件夹名称不符合要求！"))
    } else {
      callback()
    }
  }
}

export default defineComponent({
  name: 'Folder',
  emits: ['success', 'error'],
  props: {
    
  },
  components: {
    
  },
  data() {
    return {
      ruleForm: {
        folderName: ''
      },
      rules: {
        folderName: [
          { validator: validateFoldername, trigger: 'blur' }
        ]
      },
      EnhancedInfoFilled
    }
  },
  methods: {
   async handleValidate(...args) {
    await this.$refs.folder.validate(...args)
   }
  }
})
</script>

<style lang="scss">
</style>